﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.IO;
using System.Collections;
using System.Security.Cryptography;

namespace WebSocket
{
    class Program
    {
        static void Main(string[] args)
        {

            WebSocketServer webSocketServer = new WebSocketServer(IPAddress.Parse("127.0.0.1"), 5678);
            webSocketServer.OnOpen += delegate()
            {
                Console.WriteLine("opened");
            };

            webSocketServer.OnLogin += delegate(Socket socket)
            {
                Console.WriteLine("onaccepted");
            };

            webSocketServer.OnMessage += delegate(object sender, byte[] data)
            {
                webSocketServer.Broadcast(data);
            };

            webSocketServer.OnLogout += delegate(Socket socket)
            {
                Console.WriteLine("Leave one");
            };

            webSocketServer.OnHandShake += delegate(HandShake handshake) { return true; };

            // register the handshake validation
            webSocketServer.Listen();
        }
    }
}
